﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Bling.DSL;
using Bling.WPF;

namespace Bling.Tutorial {
  public class Constraints : Canvas {
    public Constraints() {
      CanvasBl canvas = this;
      SliderBl slider = new SliderBl(canvas) {
        Width = canvas.Width,
        Left = 0,
        Bottom = canvas.Height,
        Minimum = 0, Maximum = 360,
        Value = 0,
      };
      CheckBoxBl checkBox = new CheckBoxBl(canvas) {
        Height = slider.Height,
        LeftTop = slider.RightTop,
      };
      slider.Width = canvas.Width - checkBox.Width;
      checkBox.Content = checkBox.IsChecked.Condition("Red", "Blue");
      LabelBl label = new LabelBl(canvas) {
        Foreground = checkBox.IsChecked.Condition(Brushes.Red, Brushes.Blue),
        Content = "Rotate: ".Bl() + slider.Value.Round + " degrees",
        RenderTransform = { Rotate = slider.Value.ToDegrees() },
        CenterPosition = canvas.CenterSize,
        Font = { Size = 40, Weight = FontWeights.SemiBold },
      };
      ButtonBl button = new ButtonBl(canvas) {
        LeftBottom = slider.LeftTop,
        Content = "Animate",
        Click = () => {
          slider.Value = 0;
          slider.Value.Animate.Duration(500).AutoReverse().Forever().To = 360;
        },
      };
      slider.OnMouseEnter = (x, y) => {
        slider.Value.Stop(true);
        return true;
      };
      ButtonBl button2 = new ButtonBl(canvas) {
        Content = "Animate2",
        LeftBottom = button.RightBottom,
        Click = () => {
          slider.Value = 0;
          slider.Value.Animate.Duration(1000).AutoReverse().Forever().Percents(0, 0.10, 1.0).Keys(0, 180, 360);
        },
      };
      ButtonBl button3 = new ButtonBl(canvas) {
        LeftBottom = button2.RightBottom,
        Content = "Animate3",
        Click = () => {
          slider.Value = 0;
          slider.Value.Animate.Tween(t => t.Ease.Circ.Out).Duration(500).AutoReverse().Forever().To = 360;
        },
      };
      ButtonBl button4 = new ButtonBl(canvas) {
        LeftBottom = button3.RightBottom,
        Content = "Increase",
        // BAD: Click = () => slider.Value += 1,
        Click = () => slider.Value.Now += 1,
      };

    }
  }
}
